package com.zsrt.day20170401;

import java.lang.reflect.Constructor;

public class TestReflect {
	
	public static void main(String[] args) throws Exception {
		Class clazz=Class.forName("com.zsrt.day20170401.Person");
		
		System.out.println("获取除private外的构造方法---------------------");
		Constructor []constructors=clazz.getConstructors();
		for(Constructor constructor:constructors){
			System.out.println(constructor);
		}
		
		System.out.println("获取全部构造方法---------------------");
		Constructor []declaredConstructors=clazz.getDeclaredConstructors();
		for(Constructor constructor: declaredConstructors ){
			System.out.println(constructor);
		}
		
		System.out.println("获取无参构造方法---------------------");
		Constructor declaredConstructor1=clazz.getDeclaredConstructor();
		Object object=declaredConstructor1.newInstance();
		System.out.println(object instanceof Person);
		
		System.out.println("获取有参构造方法---------------------");
		Constructor declaredConstructor2=clazz.getDeclaredConstructor(int.class,String.class);
		Object object1=declaredConstructor2.newInstance(110,"张三");
		System.out.println(object1);
	}

}
